package top.fullj.remoting.consumer;

import top.fullj.remoting.ContextBase;

import java.lang.reflect.Method;

/**
 * @author bruce.wu
 * @since 2022/2/14 15:56
 */
public class InvokeContext extends ContextBase {

    private static final String SERVICE_CONFIG = "SVC_CFG";
    private static final String INVOKE_METHOD = "I_METHOD";
    private static final String INVOKE_ARGS = "I_ARGS";
    private static final String INVOKE_RESULT = "I_RET";

    public void setServiceConfig(ServiceConfig config) {
        setAttr(SERVICE_CONFIG, config);
    }

    public ServiceConfig getServiceConfig() {
        return getAttr(SERVICE_CONFIG);
    }

    public void setInvokeMethod(Method method) {
        setAttr(INVOKE_METHOD, method);
    }

    public Method getInvokeMethod() {
        return getAttr(INVOKE_METHOD);
    }

    public void setInvokeArgs(Object[] args) {
        if (args != null) {
            setAttr(INVOKE_ARGS, args);
        }
    }

    public Object[] getInvokeArgs() {
        return getAttr(INVOKE_ARGS);
    }

    public void setInvokeResult(Object result) {
        setAttr(INVOKE_RESULT, result);
    }

    public Object getInvokeResult() {
        return getAttr(INVOKE_RESULT);
    }

    public synchronized void setThrowable(Throwable t) {

    }

    public synchronized void sync(long timeout) throws InterruptedException {
        if (timeout <= 0) {
            this.wait();
        } else {
            this.wait(timeout);
        }
    }

}
